#!./perl

# ------------------------------------------------------------

# mainmenu.pl, by Jean-Pierre Girard (jpg@corrado.sun.com)
# This manages the main menu of the interface: the user is
# guided to do one step after another.

# ------------------------------------------------------------

# Bugs and other fixes

# ------------------------------------------------------------
##############################################################################
# CreatDefaultIndex: create a default index.html using _info file
##############################################################################
sub CreateDefaultIndex
{
	local($old);

	$INDEXFILENAME = "$HomeDir/$HomeName";
	unless (open (INDEXFILE, "> $INDEXFILENAME")) {
		&PrintErr("NoCreation", $INDEXFILENAME);
		#print "<H3><dd><img ALIGN=middle src=\"file:///tmp/httpd/.products/CDware/images/error.gif\">Cannot create $INDEXFILENAME</H3></dd><br>";
	}

	if (-s $INFOFILENAME && open (INFOFILE, $INFOFILENAME)) {
		$LINE=<INFOFILE>;
		($Company, $Description, $Platform, $ChosenCat, $WebSite, $Email) = split(/\^/, $LINE);
		$Product=<INFOFILE>;
		chop($Product);
		chop($Product);
		close (INFOFILE);
	}
	
	$old = select(INDEXFILE);
	#print "test\n";
	$~ = INDEX_DEFAULT;
	write;

	close(INDEXFILE);
	select($old);
}

##############################################################################
# main
##############################################################################
$BASEDIR = $ENV{"DOCUMENT_ROOT"};
require 'devinfo.pl';
require 'tools.pl';

$HomeDir = &GetDevinfo("dir");
$INFOFILENAME = $HomeDir . "/_info";

if ($ENV{'REQUEST_METHOD'} eq "POST") {
	read(STDIN, $request, $ENV{'CONTENT_LENGTH'});
} elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
	$request = $ENV{'QUERY_STRING'};
}
if (-s $INFOFILENAME && open (INFOFILE, $INFOFILENAME)) {
	$LINE=<INFOFILE>;
	($Company, $Description, $Platform, $Cat, $WebSite, $Email, $HomeName) = split(/\^/, $LINE);
	if ($HomeName eq "") {
		$HomeName = "index.html";
	}
	close (INFOFILE);
}

$~ = HEADER;
write;

$request =~ s/%(..)/pack("c",hex($1))/ge;
#print "request=$request<br>";
#print "ARGV0=$ARGV[0]<br>";
#if (@ARGV == 0 && $request eq "") {

if ($request eq "") {
	#print "in case argv=0";
} elsif ($request eq "default=Create") {
	#print "bef CreateDefault<br>";
	&CreateDefaultIndex();
} else {
	$OldHomeName=$HomeDir . "/" . $request;
	if (-s $OldHomeName) {
		if (!system("mv $OldHomeName $HomeDir/index.html")) {
			system("cd $HomeDir;ln -s ./index.html $OldHomeName");
		} else {
			&PrintErr("NoCreation", "$HomeDir/index.html");
		}
	} else {
		&PrintErr("NoExist", $OldHomeName);
	}
}

	unless (-s $HomeDir . "/_info") {
		print "<H2><li><a href=\"http://localhost:7999/cgi-bin/edit_info.pl?HTML\">Please first provide some basic information</a></H2>";
	} else {
		print "<H2><li><a href=\"http://localhost:7999/cgi-bin/edit_info.pl?HTML\">To edit the preliminary information</a></h2>";
		unless (-s "$HomeDir/$HomeName") {
			#print "<h4><li><IMG ALIGN=middle SRC=\"file:///tmp/httpd/.products/DEV/images/alert.gif\">Your \"$HomeName\" file is missing!</h4><ul>";
			print "<H2><li><a href=\"http://localhost:7999/cgi-bin/visit_html.pl?\">To create your home page and links</a></H2><br>";
			#print "<h4><li>\n<app class=\"ImageLoopItem\" img=\"file:///tmp/httpd/.products/DEV/images/blinkingAlert\" ALIGN=middle pause=5000 width=56 height=49>Your \"$HomeName\" file is missing!</h4><ul>"
			#,"<li>if your company home page exists with a different file name, please enter it here:"
			#, "<FORM method=\"post\"  ACTION=\"http://localhost:7999/cgi-bin/mainmenu.pl?\"><INPUT TYPE=\"text\" NAME=\"IsIndex\" VALUE=\"welcome.html\" SIZE=\"15\" MAXLENGTH=50> <input type=\"submit\" VALUE=\"Rename\" > </FORM>"
			#,"<H3><IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif\">If you already have HTML pages, copy them in the <b>\"$HomeDir\"</b> directory, and then reload the current page (press the <IMG ALIGN=middle SRC=\"file:///tmp/httpd/.products/DEV/images/sreload.gif\"> button at the page bottom).<br>"
			#, "<IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif\">Otherwise, please press this button to create a default home page using the information you previously entered:"
			#, "<FORM method=\"post\"  ACTION=\"http://localhost:7999/cgi-bin/mainmenu.pl?\"><input type=\"submit\" NAME=\"default\" VALUE=\"Create\" > </FORM></ul></H3>"
		} else {
			#print "<H2><li><a href=\"http://localhost:7999/cgi-bin/create_index.pl?$HomeDir/$HomeName\">To visit your main page and links</a></H2><br>";
			#print "<H2><li><a href=\"file://$HomeDir/$HomeName\">To visit your home page and links</a></H2><br>";
			print "<H2><li><a href=\"http://localhost:7999/cgi-bin/visit_html.pl?\">To edit or test your home page and links</a></H2><br>";
			#print "<H4><ul><IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_pink.gif\"><a href=\"file:///tmp/httpd/.products/DEV/tips.html\">Help and tips for designing your insertion</a></H4></ul><br>";
			#print "<H2><li><a href=\"http://localhost:7999/cgi-bin/checklinks.pl\">To check automatically your links</a></H2><br>";
			#print "Platform=$Platform<br>";
			if ($Platform =~ /^ *$/) {
				if ( -d "$HomeDir/_install") {
					&PrintErr("NoInstall");
				}
				print "<H2><li><a href=\"http://localhost:7999/cgi-bin/update.pl\">To test your complete insertion</a></H2><br>";
				print "<H2><li><a href=\"http://localhost:7999/cgi-bin/tarfiles.pl\">To send the result to SunSoft Catalyst CDware</a></H2><br>";
			} else {
				print "<H2><li><a href=\"http://localhost:7999/cgi-bin/show.pl?\">To add your slide-show or demo</a></H2><br>";
				if ( -d "$HomeDir/_install") {
					#print "<H2><li><a href=\"file:///tmp/httpd/.products/CDware/index.html\">To test your complete insertion</a></H2><br>";
					print "<H2><li><a href=\"http://localhost:7999/cgi-bin/update.pl?\">To test your complete insertion</a></H2><br>";
					print "<H2><li><a href=\"http://localhost:7999/cgi-bin/tarfiles.pl\">To send the result to Sun Microsystems</a></H2><br>";
				}
			}
		}
	}

	$~ = FOOTER;
	write;


##############################################################################
# formats
##############################################################################
format HEADER =
Content-type: text/html


<html>
<title>Developer's Kit - Main Menu</title>
<body>
#<applet code=AnimatePLUS13.class width=150 height=65>
<applet class=AnimatePLUS13 width=150 height=65>
<param name=FRAMENAME value="comp">
<param name=NUMBER value=6>
<param name=RATE value=200>
<param name=BACKGROUND value=frames/background3>
<param name=CYCLES value="infinite">
<param name=PAUSE value=2000>
<param name=POSITIONDEFAULT value=(0)&(35)>
<param name=TRANSITIONS value=SHRINK9,SHRINK9,SHRINK9,SHRINK9,SHRINK9,SHRINK9,SHRINK9,SHRINK9,SHRINK9,SHRINK9>
<param name=BORDER value=3>
<param name=BORDERCOLOR value=0,0,225>
<param name=DIMENSIONS value=240,50>
</applet>
<p><app class=ImageTape width=596 height=65 img_dir=../../../DEV/logos speed=10 dir=-10
url1=SunMicrosystem
url2=SunMicro.HotJava
url3=SunWorld
url4=SunService
url5=SunEd
url6=SunSoft.Catalyst.Flash
>
<CENTER><h1>CDware Developer's Kit - Main Menu</h1></CENTER>
<h4>Currently working with "@*
$HomeDir
" directory (Current size: @####### Kb)</h4>
`du -sk $HomeDir`
<p>Please complete each step until you send us your submission; as you complete a step, new choices will become available.
<ol type=1>
.

format FOOTER =
<h5><a href="http://localhost:7999/cgi-bin/initdev.pl?DISPLAY">Choose another company</a></h5><br>
</ol>
<hr>
<p>
You, like these companies, will benefit from the CDware capability of reaching tens of thousands of potential customers with information, links to your web site, or directly with YOUR product!
<p><app class=ImageTape width=596 height=65 img_dir=../../../DEV/logos speed=10 dir=-10
url1=oracle
url2=progress
url3=gupta
url4=informix
url5=lotus
url6=ingres
>
#</b>
<h5>If you have any comments or noticed some abnormal behavior, send us an Email: <A HREF="mailto:cdware@sun.com">cdware@sun.com</A> or call us at (415) 336-3941.</h5>
"@", "@"
<h5><p><A HREF=file:///tmp/httpd/.products/CDware/Help/SMICopyright.html>Copyright</A> 1995 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA 94043 USA.  All rights reserved.</h5><br>
<a href=file:///tmp/httpd/.products/DEV/credits.html>Credits</a>
#</b>
</body>
</html>
.

format INDEX_DEFAULT =
<html>
<title>@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< </title>
$Company
<body>
<center><img ALIGN=middle src="file:///tmp/httpd/.products/CDware/images/startup.gif"></center>
<h1>@*
$Company
</h1><p>@*
$Description
<h4>@*
$Product
: You could indicate here the description of your product(s)</h4>
<p>You can create other HTML pages that people will access through this page, to provide details about your products, prices, distributors, events where your company will be present....</p>
<hr><b>
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Company
</b><br>Street number and name<br>
City, St Zip<br>
Country.<br>
Phone: (area)....<br>
Fax: (area)...<br>
<h5>To contact our sales services or ask for more information:<A HREF="mailto:@*
$Email
">@*
$Email
</A></H5>
<h5>To visit our web site:<A HREF="http://@*
$WebSite
">http://@*
$WebSite
/</A></H5>
<body><html>
.
